package jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * JDBC java数据库连接
 */
public class JDBCDemo3 {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        // 1.注册驱动Class.forName()
        Class.forName("com.mysql.cj.jdbc.Driver");
        // 2.建立连接DriverManager.getConnection()
        String url = "jdbc:mysql://localhost:3307/birdbootdb?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true";
        Connection connection = DriverManager.getConnection(url, "root", "root");
        // 3.创建Statement对象
        Statement statement = connection.createStatement();
        String sql = "UPDATE userinfo " +
                "SET age=56 " +
                "WHERE username='张三'";
        int sum = statement.executeUpdate(sql);
        System.out.println("修改了表中" + sum + "条记录");

        connection.close();
    }
}
